package yxy.game.pm2.module.union.boss;

import java.util.HashSet;
import java.util.Map;

import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.unionbossdamagereward;
import yxy.cherry.data.script.fomula;
import yxy.cherry.data.string.GameString;
import yxy.game.pm2.bean.Currency;
import yxy.game.pm2.bean.currency.Currencies;
import yxy.game.pm2.bean.mq.CCReason;
import yxy.game.pm2.module.mail.MailHandle;
import yxy.game.pm2.module.mail.MailTypeEnum;

public class UnionPlayerBoss {
    // bean===========================================================================

    private long bossId;// 上次挑战的bossId
    private long damage;// 上次的伤害

    private int times;// 今天的挑战次数
    private int buytimes;// 今天的购买次数
    private long totalDamageForDay; //当天累计伤害

    public long getTotalDamageForDay() {
        return totalDamageForDay;
    }

    public void setTotalDamageForDay(long totalDamageForDay) {
        this.totalDamageForDay = totalDamageForDay;
    }

    private HashSet<String> bossReward = new HashSet<>();// 摸过奖励的boss

    public long getBossId() {
        return bossId;
    }

    public void setBossId(long bossId) {
        this.bossId = bossId;
    }

    public long getDamage() {
        return damage;
    }

    public void setDamage(long damage) {
        this.damage = damage;
    }

    public int getTimes() {
        return times;
    }

    public void setTimes(int times) {
        this.times = times;
    }

    public int getBuytimes() {
        return buytimes;
    }

    public void setBuytimes(int buytimes) {
        this.buytimes = buytimes;
    }

    public HashSet<String> getBossReward() {
        return bossReward;
    }

    public void setBossReward(HashSet<String> bossReward) {
        this.bossReward = bossReward;
    }

    // func===========================================================================

    public void update(String code) {
        setDamage(0);
        setTimes(0);
        setBuytimes(0);

        //发奖励并重置伤害
        long damage = getTotalDamageForDay();
        if (damage != 0) {
            long condition = 0;
            unionbossdamagereward data = null;
            Map<String, unionbossdamagereward> allData = DataCenter.getAllData(unionbossdamagereward.class);
            for (unionbossdamagereward value : allData.values()) {
                if (value.getCondition() <= damage && value.getCondition() > condition) {
                    condition = value.getCondition();
                    data = value;
                }
            }

            //发奖励
            if (data != null) {
                Currencies rewards = new Currencies(Currency.create(data.getRewardtype(), data.getRewardid(), data.getRewardnum())); //奖励
                String title = GameString.联盟boss伤害当天奖励_title().getText();
                String content = GameString.联盟boss伤害当天奖励_msg(damage).getText();
                //邮件发送奖励
                new MailHandle().sendMail(code, MailTypeEnum.Mail, title, content, CCReason.联盟BOSS, rewards);
            }
        }
        setTotalDamageForDay(0);
    }

    public long damage(int bossId) {
        if (bossId != getBossId()) {
            setDamage(0);
        }
        return getDamage();
    }

    /**
     * 剩余购买
     */
    public int buytimes() {
        int num = fomula.联盟boss每日购买次数.intValue() - getBuytimes();
        return num < 0 ? 0 : num;
    }

    /**
     * 剩余挑战
     */
    public int times() {
        int num = fomula.联盟boss每日初始挑战次数.intValue() - getTimes();
        return num < 0 ? 0 : num;
    }

    public static UnionPlayerBoss create() {
        UnionPlayerBoss module = new UnionPlayerBoss();
        return module;
    }

}
